package org.tinygroup.springmvc.negotiation.impl;
import java.util.Collections;
import java.util.List;

import org.springframework.http.MediaType;
import org.springframework.web.context.request.NativeWebRequest;
import org.tinygroup.logger.LogLevel;
import org.tinygroup.logger.Logger;
import org.tinygroup.logger.LoggerFactory;
import org.tinygroup.springmvc.negotiation.ContentNegotiationStrategy;

/**
 * 返回固定的MediaType
 *
 *@author renhui
 */
public class FixedContentNegotiationStrategy implements ContentNegotiationStrategy {

	private static final Logger LOGGER = LoggerFactory.getLogger(FixedContentNegotiationStrategy.class);

	private final MediaType defaultContentType;

	/**
	 * Create an instance that always returns the given content type.
	 */
	public FixedContentNegotiationStrategy(MediaType defaultContentType) {
		this.defaultContentType = defaultContentType;
	}

	public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest) {
		LOGGER.logMessage(LogLevel.DEBUG, "Requested media types is {0} (based on default MediaType)",this.defaultContentType);
		return Collections.singletonList(this.defaultContentType);
	}

}